package com.java.advance.clazz.loader;

/**
 * 用于掩饰类的初始化顺序的
 * Created by yangminghua on 2019/4/3.
 */
public class ClassInitDemo {
    public static void main(String[] args) {
        ParentDemo parentDemo = new ChildDemo();
    }

    static {
        System.out.println("ClassInitDemo init");
    }

    public ClassInitDemo() {
        System.out.println("ClassInitDemo的构造方法");
    }


}

class ParentDemo {
    String name;

    static {
        System.out.println("父类的静态方法1");
    }

    /**
     * 有参构造器
     *
     * @param name
     */
    public ParentDemo(String name) {
        this.name = name;
        System.out.println("父类的有参构造方法");
    }

    /**
     * 无参构造器
     */
    public ParentDemo() {
        System.out.println("父类的构造方法");
    }

    ThirdDemo thirdDemo = new ThirdDemo();

    static {
        System.out.println("父类的静态方法2");
    }

    public static void main(String[] args) {
        ParentDemo parentDemo = new ChildDemo();
    }

}

class ChildDemo extends ParentDemo {

    int age;

    static {
        System.out.println("ChildDemo的静态方法1");
    }

    public ChildDemo(int age) {
        this.age = age;
        System.out.println("ChildDemo的有参构造方法");

    }

    public ChildDemo() {
        System.out.println("ChildDemo的构造方法");
    }

    FourDemo fourDemo = new FourDemo();

    static {
        System.out.println("ChildDemo的静态方法2");
    }
}

class ThirdDemo {

    public ThirdDemo() {
        System.out.println("ThirdDemo构造器被执行");
    }

    static {
        System.out.println("ThirdDemo静态块被执行");
    }


}

class FourDemo {
    public FourDemo() {
        System.out.println("FourDemo构造器被执行");
    }

    static {
        System.out.println("FourDemo静态块被执行");
    }
}
